#!/bin/bash
count=$#
if [ $count > 0 ] && [ "$1" == "r" ]; then
  OUT_DIR='Bin.Release'
  BUILD_DIR='Build.Release'
  build_params="-D CMAKE_BUILD_TYPE=Release"
else
  OUT_DIR='Bin.Debug'
  BUILD_DIR='Build.Debug'
  build_params="-D CMAKE_BUILD_TYPE=Debug"
fi

if [ ! -d "build" ]; then
    mkdir "build"
fi

cd build

if [ ! -d $BUILD_DIR ]; then
    mkdir $BUILD_DIR
fi

if [ ! -d $OUT_DIR ]; then
  mkdir $OUT_DIR
fi

echo $build_params
cmake $build_params -D CMAKE_RUNTIME_OUTPUT_DIRECTORY=./$OUT_DIR ..
make